﻿using Microsoft.AspNetCore.Mvc;
using Models.Common;
using Models.JsonResultModel;

namespace FileServer.Common
{
    /// <summary>
    /// Json帮助类
    /// </summary>
    public class ReturnJsonResult
    {
        // public string respCode { get; set; }
        //public string respMsg { get; set; }
        public ReturnJsonResult()
        {
            // respCode = "";
            //respMsg = "";
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="rtnData"></param>
        /// <returns></returns>
        public static JsonResult Sucess(object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = ResponseCode.SUCCESS,
                respMsg = ResponseCode.SUCCESS_MSG,
                data = rtnData ?? string.Empty
            };
            //JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
            //jsonSerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            return new JsonResult(RespResultData);
        }

        //错误返回
        public static JsonResult Faild(string responseMessage = "", string responseCode = null, object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = responseCode ?? ResponseCode.System_ERROR,
                respMsg = responseMessage ?? string.Empty,
                data = rtnData ?? string.Empty
            };
            return new JsonResult(RespResultData);
        }



        public static JsonResult NotAuthorize(string responseMessage, string responseCode = "90", object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = responseCode,
                respMsg = responseMessage ?? string.Empty,
                data = rtnData ?? string.Empty
            };
            return new JsonResult(RespResultData);
        }


    }
}